package com.louis.domain.i18n;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.louis.domain.DomainObject;

import java.text.MessageFormat;
import java.util.Locale;

/**
 * 
 * <p>
 * Translation
 * </p>
 * 
 * @author: louisjiang
 * @version: 1.0.0,Apr 23, 20124:45:29 PM
 */
@Entity
@Table(name = "translation")
public class Translation extends DomainObject {

	private static final long		serialVersionUID	= 6729699981447575397L;

	private String					language;

	private String					text;

	@ManyToOne(optional = true)
	@JoinColumn(name = "messageid")
	private Message					message;

	private transient MessageFormat	messageFormat;

	public Translation() {
	}

	public Translation(String language, String text, Message message) {
		this.language = language;
		this.text = text;
		this.message = message;
	}

	public String getLanguage() {
		return language;
	}

	public void setLanguage(String language) {
		this.language = language;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public MessageFormat getMessageFormat() {
		if (messageFormat == null) {
			messageFormat = new MessageFormat(text, getLocale());
		}
		return messageFormat;
	}

	public Locale getLocale() {
		return new Locale(this.language);
	}

	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}
}